package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.vo.AdminPagePledgeTaskVO;
import com.sc.nft.entity.vo.SecretAreaPageVO;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.PledgeTaskInfo;
import com.sc.nft.mapper.PledgeTaskInfoMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

/**
 * 质押任务(秘境)主表(sc_pledge_task_info)数据DAO
 *
 * @author Sun
 * @since 2023-06-12 15:36:35
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class PledgeTaskInfoDao extends ServiceImpl<PledgeTaskInfoMapper, PledgeTaskInfo> {

    public Page<AdminPagePledgeTaskVO> adminPagePledgeTask(String pledgeTaskName, Integer pageNo, Integer pageSize) {
        return baseMapper.adminPagePledgeTask(new Page<>(pageNo, pageSize), pledgeTaskName);
    }

    public Boolean updateIsEnableById(Long id, Boolean isEnable) {
        UpdateWrapper<PledgeTaskInfo> wrapper = new UpdateWrapper<>();
        wrapper.eq("id", id);
        wrapper.set("is_enable", isEnable);
        return update(new PledgeTaskInfo(),wrapper);
    }

    public Boolean adminUpdatePledgeTaskIsSort(Long id, Integer sort) {
        UpdateWrapper<PledgeTaskInfo> wrapper = new UpdateWrapper<>();
        wrapper.eq("id", id);
        wrapper.set("sort", sort);
        return update(new PledgeTaskInfo(),wrapper);
    }

    public boolean updatePledgeTaskJoinCount(Long id, Integer joinCount) {
        UpdateWrapper<PledgeTaskInfo> wrapper = new UpdateWrapper<>();
        wrapper.eq("id", id);
        wrapper.set("join_count", joinCount);
        return update(new PledgeTaskInfo(),wrapper);
    }

    public Page<SecretAreaPageVO> secretAreaPage(Integer pageNo, Integer pageSize) {
        return baseMapper.secretAreaPage(new Page<>(pageNo, pageSize));
    }

    public Boolean updateJoinCount(Long pledgeTaskId) {
        return baseMapper.updateJoinCount(pledgeTaskId);
    }
}